"use strict";

/**
 * @ngdoc function
 * @name jgappApp.controller:RemarkIndexCtrl
 * @description
 * # RemarkIndexCtrl
 * Controller of the jgappApp
 */
angular
  .module("jgappApp")
  .controller("RemarkIndexCtrl", function (
    localStorageService,
    $location,
    DataService,
    openApi,
    Util,
    $routeParams
  ) {
    var vm = this;
    vm.data = {}
    this.choosepeople = function () {
      localStorageService.set("chooseUsrs", vm.data.followList);
      localStorageService.set("flowremark", vm.data);
      // getFollows是要访问的接口
      $location.path("chooseuser/index/getFollows");
    };
    vm.delpersons = function (index) {
      vm.data.followList.splice(index, 1);
    };
    this.addDatamemo = function () {
      if (!this.data.memo) {
        Util.Toast("请输入备注内容");
        return;
      }
      this.data.dateId = $routeParams.uid;
      this.data.formkey = Util.getformKey();
      this.data.userIds = vm.data.followList.map(function (user) {
        return user.id
      });
      DataService.getData(openApi.addDatamemo, this.data).then(function (data) {
        if (data) {
          Util.Toast("添加备注成功");
          Util.goBack()
        }
      });
    };
    function init() {
      var chooseUsrs = localStorageService.get("chooseUsrs");
      localStorageService.remove("chooseUsrs");
      vm.data = localStorageService.get("flowremark") || {}
      vm.data.followList = chooseUsrs || vm.data.followList || [];
    }

    init()
  });
